package com.medical.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.medical.dao.SysMenuMapper;
import com.medical.dao.SysRoleMapper;
import com.medical.dao.SysRoleMenuMapper;
import com.medical.dao.SysUserRoleMapper;
import com.medical.entity.SysRoleMenu;
import com.medical.entity.SysUserRole;

@Service
@Transactional
public class RoleService {
	
	@Autowired
	private SysRoleMapper roleMapper;
	@Autowired
	private SysRoleMenuMapper roleMenuMapper;
	@Autowired
	private SysMenuMapper menuMapper;
	@Autowired
	private SysUserRoleMapper userRoleMapper;
	
	/**
	 * 根据用户ID获取用户拥有菜单列表
	 * @param userId
	 * @return
	 */
	public List<String> getUserPermissions(String userId) {
		List<String> strList=new ArrayList<String>();
		// 根据用户ID获取用户角色关联关系，即该用户拥有多少角色
		List<SysUserRole> userRoleList = userRoleMapper.getUserRoleList(userId);
	        for (int i = 0; i < userRoleList.size(); i++){
	            List<SysRoleMenu> roleRightList = new ArrayList<SysRoleMenu>();
	            // 获取角色菜单关联关系，即角色拥有多少菜单
	            roleRightList = roleMenuMapper.getRoleMenuList(userRoleList.get(i).getRoleId());
	            for (int j = 0; j < roleRightList.size(); j++){
	                strList.add(roleRightList.get(j).getMenuId());
	            }
	        }
		
		return strList;
	}

}
